# 导包
from selenium import webdriver
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 创建浏览器驱动对象
driver = webdriver.Edge(r"C:\ProgramData\Anaconda3\msedgedriver.exe")
driver.maximize_window()

# 打开页面
driver.get(r"file:///D:\Downloads\ALiYunDrive\学习\计算机大三下\软件测试\实验8 Selenium API示例代码实验（一）\Selenium API示例代码\html\注册A.html")

# 在用户名文本框上点击鼠标右键
action = ActionChains(driver)
action.context_click(driver.find_element_by_id("userA"))
action.perform()

# 输入用户名admin，暂停3秒钟后，双击鼠标左键，选中admin
element = driver.find_element_by_id("userA")
element.send_keys("admin")
time.sleep(3)
ActionChains(driver).double_click(element).perform()

# 模拟鼠标悬停在‘注册’按钮上
time.sleep(10)
ActionChains(driver).move_to_element(driver.find_element_by_tag_name("button")).perform()

# 暂停3秒
time.sleep(3)

# 关闭驱动
driver.quit()
